package com.apexedu.eas.service.impl;

import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.apexedu.eas.dao.impl.MsgDao;
import com.apexedu.eas.entity.test.Message;
import com.apexedu.eas.service.MsgService;
import com.apexedu.eas.util.DXPTUtil;

@Service
public class MsgServiceImpl implements MsgService {

	@Autowired
	private MsgDao msgDao;
	/**
	 * key=id value=seqId
	 */
	public static Map<String, Integer> map;

	public static Map<String, Integer> map2;

	@Override
	public void sendMsgTask() {
		// TODO Auto-generated method stub
		map = new ConcurrentHashMap<String, Integer>();
		map2 = new ConcurrentHashMap<String, Integer>();
		List<Message> messages = this.msgDao.queryNoSend();
		for (Message message : messages) {
			if (message.getSjh() == null) {
				continue;
			}
			try {
				String result = (String) DXPTUtil.sendMsg(message);
				if (result != null) {
					map.put(result, message.getId());
				}
			} catch (IOException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
		if (messages.size() <= 0) {
			System.out.println("无短信");
		}
	}


	@Override
	public Integer updateStatus(Integer zt, String sendTime, Integer id) {
		return this.msgDao.updateStatus(zt, sendTime, id);
	}

}
